package com.wiki4j.gdo.type;

import java.math.BigDecimal;

import com.wiki4j.gdo.GDTypes;
import com.wiki4j.gdo.impl.JSON;

public abstract class AbstractGDTypeBase implements GDTypeBase{
  @Override
  public String namespace(){
    return GDTypes.GDO_NS;
  }

  @Override
  public String getFullName(){
    return namespace()+"."+name();
  }

  @Override
  public boolean isContainer(){
    return false;
  }

  @Override
  public String toString(Object src){
    if(src==null) return null;
    return src.toString();
  }

  @Override
  public int toInt(Object src){
    if(src instanceof Integer) return (int)src;
    return Integer.parseInt(src.toString());
  }

  @Override
  public long toLong(Object src){
    if(src instanceof Long) return (long)src;
    return Long.parseLong(src.toString());
  }

  @Override
  public double toDouble(Object src){
    if(src instanceof Double) return (double)src;
    return Double.parseDouble(src.toString());
  }

  @Override
  public boolean toBoolean(Object src){
    if(src instanceof Boolean) return (boolean)src;
    return Boolean.parseBoolean(src.toString());
  }

  @Override
  public BigDecimal toBigDecimal(Object src){
    if(src instanceof BigDecimal) return (BigDecimal)src;
    return new BigDecimal(src.toString());
  }

  @Override
  public String toJson(){
    return JSON.toJson(this);
  }

  @Override
  public String toString(){
    return toJson();
  }
}
